package com.woniu.service.impl;

import com.woniu.entity.Users;
import com.woniu.mapper.UserMapper;
import com.woniu.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements com.woniu.service.UserService {
    SqlSession sqlSession = MyBatisUtil.getSqlSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    @Override
    public Users serviceUserLogin(String username, String pwd) {
        Users user = mapper.selectUser(username, pwd);
        return user;

    }

    @Override
    public void updateUsersMoney(Integer uid, Double price) {
        mapper.updateUser(uid,price);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void insertUser(Users users) {
        mapper.insertUser(users);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Users selectUserByName(String username) {
        Users users = mapper.selectUserByName(username);
        return users;
    }

    @Override
    public List<Users> selectAllUsersByPowerId(Integer power_id) {
        List<Users> users = mapper.selectAllUsersByPowerId(power_id);
        return users;
    }

    @Override
    public void deleteUserById(Integer uid) {
        mapper.deleteUserById(uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Users selectUserByUid(int userId) {
        Users users = mapper.selectUserByUid(userId);
        return users;
    }

    @Override
    public void updateUserName(String username,Integer uid) {
        mapper.updateUserName(username,uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateUserPwd(String pwd,Integer uid) {
        mapper.updateUserPwd(pwd,uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateUserTelphone(String telphone,Integer uid) {
        mapper.updateUserTelphone(telphone,uid);
        sqlSession.commit();
        sqlSession.close();
    }

}
